package com.liu.spider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.spider.entity.Task;
import com.liu.spider.mapper.TaskMapper;
import com.liu.spider.service.ITaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 定时任务表 服务实现类
 * </p>
 *
 * @author liu
 * @since 2021-12-29
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {

    @Autowired
    private TaskMapper taskMapper;

    @Override
    public int insertTask(Task task) {
        return taskMapper.insert(task);
    }

    @Override
    public List<Task> getTaskListByStatus(String jobStatus) {
        QueryWrapper<Task> wrapper = new QueryWrapper<>();
        wrapper.eq("job_status",jobStatus);
        return taskMapper.selectList(wrapper);
    }

    public List<Task> getTaskList(Integer page) {
        QueryWrapper<Task> wrapper = new QueryWrapper<>();
        return taskMapper.selectPage(new Page<Task>(page,10),wrapper).getRecords();
    }

    @Override
    public Task findTaskByJobId(Long id) {
        return taskMapper.selectById(id);
    }

    @Override
    public boolean deleteTaskByJobId(Long id) {
        return taskMapper.deleteById(id)> 0 ? true : false;
    }

    @Override
    public boolean updateTask(Task task) {
        return taskMapper.updateById(task)> 0 ? true : false;
    }
}
